package com.huatech.common;

import java.io.Serializable;

import org.springframework.http.ResponseEntity;
/**
 * 
 * @author lihua_java@163.com
 *
 * @param <T>
 */
public class Result<T> implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private int code = 0;	// 响应码
	private String msg;		// 响应描述
	private T data;			// 接口数据
	public int getCode() {
		return code;
	}
	public void setCode(int code) {
		this.code = code;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	public T getData() {
		return data;
	}
	public void setData(T data) {
		this.data = data;
	}
	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	
	public Result(int code, String msg, T data) {
		super();
		this.code = code;
		this.msg = msg;
		this.data = data;
	}
	public static <T> Result<T> result(CodeEnum code) {
        return result(code, null);
    }

    public static <T> Result<T> result(CodeEnum code, T result) {
        return new Result<T>(code.getCode(), code.getMsg(), result);
    }
    
	
	public static ResponseEntity<?> ok(){
		return ResponseEntity.ok(result(CodeEnum.CODE_OK));
    }

    public static <T> ResponseEntity<?> ok(T data){
    	return ResponseEntity.ok(result(CodeEnum.CODE_OK, data));
    }

    public static <T> ResponseEntity<?> fail(CodeEnum code){
        return  ResponseEntity.ok(result(code));
    }

}
